#pragma once

#include<iostream>
using namespace std;

template<class T>
class interval
{
private:
	T upper;
	T lower;
	T Tal;
public:

	interval(void)
	{
		upper=0;
		lower=0;
	}
	interval(T tal)
	{
		Tal=tal;
	}

	interval(T mean, double procent)
	{
		lower=mean - mean * procent / 100;
		upper=mean + mean * procent / 100;
	}

	T mean() 
	{ return (lower+upper)/2; }

	double relative_error() 
	{ 
		return (upper-lower) / mean();
	}

	void print_relative()
	{
		cout << "mean=" << mean() << ", relative error = " << relative_error()  << endl;
	}

	friend interval<T> operator-(interval<T> &lop, interval<T> &rop )
	{
		interval<T> m;

			m.upper = lop.lower-rop.upper;
			m.lower = lop.upper-rop.lower;
			return m;
	}

		friend interval<T> operator+(interval<T> &lop, interval<T> &rop )
		{
			interval<T> m;

			m.upper = lop.upper+rop.upper;
			m.lower = lop.lower+rop.lower;
			return m;
		}

		friend ostream& operator<<(ostream &out, const interval<T> &rop)
		{
			if(rop.upper>0)
			{
			out << "[" << rop.lower << "," << rop.upper << "]";
			}
			else
			{
				out << "[" << rop.upper << "," << rop.lower << "]";
			}
			return out;
		}



		~interval(void)
		{
		}
	};

